package com.dmcb.common.business.utils;


import org.apache.commons.lang3.StringUtils;

/**
 * Created by long on 2015/3/29.
 */
public class IntUtil {

    private static final String X36 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    //10进制转换成36进制
    public static String to36(int val) {
        String result = "";
        while (val >= 36) {
            result = X36.charAt(val % 36) + result;
            val /= 36;
        }
        if (val >= 0) result = X36.charAt(val) + result;
        return result;
    }

    //36进制转换成10进制
    public static int to10From36(String str) {
        if (StringUtils.isBlank(str)) {
            return 0;
        }
        int result = 0;
        int len = str.length();
        for (int i = len; i > 0; i--) {
            result += X36.indexOf(str.charAt(i - 1)) * Math.pow(36, len - i);
        }
        return result;
    }

}
